The width, in pixels, of any room in the project - not only the one you are in. Handy before you go there, for example to place something inside the next room with room_change_ext.
room_width_of(r) -> int| Name | Type |
|---|---|
r | room |
int
Gives back the width, in pixels, of a room you name, even when it is not the room you are standing in. room_width only ever answers for the current room. room_width_of answers for any room in your project.
The reason it exists is room_change_ext. That function puts something at an x and y inside the next room, and a position only means something once you know how big that room is. The x and y you give it are counted from the top-left corner of that next room, so the room's size is what tells you where its middle or its far edge is. With room_width_of, you can ask the room how wide it is and work out the spot you meant, such as its middle, without writing the number down.
A room's size is not one fixed number, because every room can be a different size, so this is worked out when the game runs. If what you give it is not a room, it gives back 0 and does nothing else. It never crashes.
var middle = room_width_of(room_doc_arena) / 2;Asks how wide room_doc_arena is and halves it, giving the x of that room's middle, counted from its top-left corner (so its left edge is 0). Nothing has to load room_doc_arena first.
A run-time read of that room’s size from the project’s room table, so the room does not need to be loaded. A value that is not a room gives 0, the same quiet answer room_width gives when there is no room.